<?php

declare(strict_types=1);

namespace App\Amqp\Consumer;

use Hyperf\Amqp\Result;
use Hyperf\Amqp\Message\Type;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Logger\LoggerFactory;
use PhpAmqpLib\Message\AMQPMessage;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;

#[Consumer(exchange: 'ext.hyperf.delay', routingKey: '', queue: 'queue.hyperf.delay', name: "DelayDirectConsumer", nums: 1)]
class DelayDirectConsumer extends ConsumerMessage
{
    use ProducerDelayedMessageTrait;
    use ConsumerDelayedMessageTrait;

    protected Type|string $type = Type::DIRECT;

    #[Inject]
    private LoggerFactory $logger;

    public function consumeMessage($data, AMQPMessage $message): Result
    {
        $this->logger->get('queue')->info('Receive delay message: ', $data);
        return Result::ACK;
    }
}
